layui.define(['element', 'api','utils','amis', 'header_right', 'publish'], function(exports) {
    "use strict";

    /**
     * Button component
     * */
    var MOD_NAME = 'header',
        $ = layui.jquery,
        utils = layui.utils,
        header_right = layui.header_right,
        publish= layui.publish,
        api = layui.api,
        amis = layui.amis
    ;

    var editor_header = function(opt) {
        this.option = opt;
    };

    function addDom(option){
        var dom = `
              <div class="content">
                <div class="header">
                    <div class="header-left" >
                        <div id="header-left"></div>
                    </div>
                    <div class="header-center">
                    </div>
                    <div class="header-right">
                    </div>
                </div>
            </div>
        `
        $(option.elem).append(dom);
    }


    /**
     * Button start loading
     * */
    editor_header.prototype.render = function(opt) {

        var option = {
            elem: opt.elem,
            publishSettings: opt.publishSettings,
            resourceToolbarSettings: opt.resourceToolbarSettings
        }

        //渲染右边
        renderRight(option);

        //渲染发布
        if(option.publishSettings){
            option.publishSettings.elem = '.header-center';
            publish.render(option.publishSettings);
        }


        return new editor_header(option);
    }


    function renderRight(option){
        addDom(option);

        var resourceToolbarSettings = option.resourceToolbarSettings;
        if(option.resourceToolbarSettings){
            option.resourceToolbarSettings.elem = '.header-right'
            header_right.render(option.resourceToolbarSettings);
        }
    }


    exports(MOD_NAME, new editor_header());
});
